{extend name="light-year/layout/default" /}

{block name="title"}数据库管理{/block}

{block name="content"}
<div class="card-toolbar clearfix">
    <div class="toolbar-btn-action">
        <a class="btn btn-dark" href="javascript:;" onclick="batchOptimizationOrRepair('{:url(\'optimizationAll\')}', '修复');">
            <i class="mdi mdi-crop-rotate"></i> 批量修复
        </a>
        <a class="btn btn-success" href="javascript:;" onclick="batchOptimizationOrRepair('{:url(\'repairAll\')}', '优化');">
            <i class="mdi mdi-repeat"></i> 批量优化
        </a>
        <a class="btn btn-danger" href="javascript:;" onclick="batchBackup('{:url(\'backup\')}');">
            <i class="mdi mdi-backup-restore"></i> 备份与还原
        </a>
        <a class="btn btn-info m-r-5" href="javascript:;" onclick="batchExport('{:url(\'export\')}');"><i class="mdi mdi-export"></i> 导出 </a>
    </div>
    <hr>
</div>
<div class="card-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th class="text-center">
                    <label class="lyear-checkbox checkbox-primary">
                        <input type="checkbox" id="check-all"><span></span>
                    </label>
                </th>
                <th class="text-center"> 数据表名称与注释 </th>
                <th class="text-center"> 存储引擎 </th>
                <th class="text-center"> 总行数 </th>
                <th class="text-center"> 平均行长度 </th>
                <th class="text-center"> 数据长度 </th>
                <th class="text-center hidden-sm hidden-xs"> 索引长度 </th>
                <th class="text-center hidden-sm hidden-xs"> 创建时间 </th>
                <th class="text-center hidden-sm hidden-xs"> 更新时间 </th>
                <th class="text-center hidden-sm hidden-xs"> 字符校验编码 </th>
                <th class="text-center"> 操作 </th>
            </tr>
            </thead>
            <tbody>
            {if !empty($list)}
            {foreach $list as $key => $item}
            <?php // var_dump($item);exit;?>
            <tr id="id_{$item->Name}" name="{$item->Name}">
                <td class="text-center">
                    <label class="lyear-checkbox checkbox-primary">
                        <input type="checkbox" name="name[]" value="{$item->Name}"><span></span>
                    </label>
                </td>
                <td class="text-center">
                    <a href="javascript:;">{$item->Name}</a>
                    <br>
                    {$item->Comment}
                </td>
                <td class="text-center"> {$item->Engine} </td>
                <td class="text-center"> {$item->Rows} </td>
                <td class="text-center"> {$item->Avg_row_length} </td>
                <td class="text-center"> {$item->Data_length} </td>
                <td class="text-center hidden-sm hidden-xs"> {$item->Index_length} </td>
                <td class="text-center hidden-sm hidden-xs"> {$item->Create_time} </td>
                <td class="text-center hidden-sm hidden-xs"> {$item->Update_time} </td>
                <td class="text-center hidden-sm hidden-xs"> {$item->Collation} </td>
                <td class="text-center">
                    <a class="btn btn-xs btn-primary" title="修复“{$item->Name}”表" onclick="optimizationOperation('{$item->Name}', '{:url(\'optimization\')}')">
                        <i class="mdi mdi-crop-rotate"></i>
                        修复表
                    </a>
                    <a class="btn btn-xs btn-info" title="优化“{$item->Name}”表" onclick="repairOperation('{$item->Name}', '{:url(\'repair\')}')">
                        <i class="mdi mdi-repeat"></i>
                        优化表
                    </a>
                </td>
            </tr>
            {/foreach}
            {/if}
            </tbody>
        </table>
    </div>
</div>
{/block}

{block name="script-src"}
{/block}

{block name="script"}
<script type="text/javascript">
    function batchOptimizationOrRepair(api_url, msg) {
        layer.confirm('确定要进行“批量-' + msg + '表”操作吗？\b\b 删除之后将无法恢复！', {title: webTitle}, function () {
            layerLoading();
            axios.post( api_url).then(function(data){
                if (data.status == 1){
                    layerMsg(data.msg, 1, layerJumpTime, 2);
                } else layerMsg(data.msg, 5, layerJumpTime);
            }).catch(function(res){
            });
        }, function () {
        });
    }
</script>
{/block}